package com.kc.business.service.impl;

import com.kc.business.domain.BizOss;
import com.kc.business.mapper.BizOssMapper;
import com.kc.business.service.IBizOssService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

import java.util.List;

@Service("bizOssService")
public class BizOssServiceImpl implements IBizOssService {
    @Autowired
    private BizOssMapper bizOssMapper;

    /**
     * 文件列表
     *
     * @param bizOss
     * @return
     */
    @Override
    public List<BizOss> getList(BizOss bizOss) {
        Example example = new Example(BizOss.class);
        Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(bizOss.getFileName())) {
            criteria.andLike("fileName", "%" + bizOss.getFileName() + "%");
        }
        if (StringUtils.isNotBlank(bizOss.getFileSuffix())) {
            criteria.andEqualTo("fileSuffix", bizOss.getFileSuffix());
        }
        if (StringUtils.isNotBlank(bizOss.getCreateBy())) {
            criteria.andLike("createBy", bizOss.getCreateBy());
        }
        return bizOssMapper.selectByExample(example);
    }

    /**
     * 保存
     *
     * @param ossEntity
     * @return
     */
    @Override
    public int save(BizOss ossEntity) {
        return bizOssMapper.insertSelective(ossEntity);
    }

    @Override
    public BizOss findById(Long ossId) {
        return bizOssMapper.selectByPrimaryKey(ossId);
    }

    @Override
    public int update(BizOss bizOss) {
        return bizOssMapper.updateByPrimaryKeySelective(bizOss);
    }

    @Override
    public int deleteByIds(String ids) {
        return bizOssMapper.deleteByIds(ids);
    }
}
